Imports KanBan.Pgd.Infrastructure.Exceptions
Imports KanBan.Pgd.Presentation.Helpers
Imports KanBan.Pgd.Services
Imports KanBan.Pgd.Domain.Extensions
Imports KanBan.Pgd.Domain.Entities

Public Class EditUserProfile

    Private Const DefaulGridViewRowHeight As Integer = 36

    Private app As New PgdApp()

    Public Sub New(ByVal userId As Guid)

        Try

            ' This call is required by the Windows Form Designer.
            InitializeComponent()

            ' Add any initialization after the InitializeComponent() call.

            Me.InitializeView(userId)

        Catch ex As Exception

            FormHelper.ShowError(ExceptionHandler.HandleException(ex))

        End Try

    End Sub

    Private Sub InitializeView(ByVal userId As Guid)

        Me.LoadUserCompetencies(userId)

    End Sub

    Private Sub LoadUserCompetencies(ByVal userId As Guid)

        Dim userCompetencies = app.Users.GetCompetencies(userId)

        For Each uc In userCompetencies
            Me.AddUserCompetency(uc)
        Next

    End Sub

    Private Sub AddUserCompetency(ByVal uc As UserCompetency)

        Dim row As New DataGridViewRow()
        row.CreateCells(grvUserCompetencies)
        row.Height = DefaulGridViewRowHeight

        row.Cells(GridColumns.CompetencyId).Value = uc.Competency.Id
        row.Cells(GridColumns.Name).Value = uc.Competency.Name
        row.Cells(GridColumns.Level).Value = uc.KnoledgeLevel.GetDescription()

        grvUserCompetencies.Rows.Add(row)

    End Sub

    Private Enum GridColumns
        Image = 0
        CompetencyId = 1
        Name = 2
        Level = 3
        Edit = 4
        Delete = 5
    End Enum

    Private Sub btnNew_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnNew.Click

        Me.AddNewUserCompetency()

    End Sub

    Private Sub AddNewUserCompetency()

        'Dim form As New EditUserCompetency()
        'FormHelper.ShowAsChildForm(Me, form)

    End Sub

End Class